package com.wjw.controller;

import com.wjw.pojo.bo.ShopcartBO;
import com.wjw.utils.WJWJSONResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 2 * @Author: 小王同学
 * 3 * @Date: 2020/12/20 16:29
 * 4
 */
@RestController
@RequestMapping("shopcart")
@Api(value = "购物车接口controller", tags = {"购物车接口相关的api"})
public class ShopcartController {

    @ApiOperation(value = "添加商品到购物车", notes = "添加商品到购物车", httpMethod = "POST")
    @PostMapping("/add")
    public WJWJSONResult add(@RequestParam String userId, @RequestBody ShopcartBO shopcartBO,
                             HttpServletRequest request, HttpServletResponse response) {

        if (StringUtils.isBlank(userId)){
            return WJWJSONResult.errorMsg("");
        }

        System.out.println(shopcartBO);

        // TODO 前端用户在登录的情况下，添加商品到购物车，会同时在后端同步购物车到redis

        return WJWJSONResult.ok();
    }


    @ApiOperation(value = "从购物车中删除商品", notes = "从购物车中删除商品", httpMethod = "POST")
    @PostMapping("/del")
    public WJWJSONResult del(@RequestParam String userId, @RequestParam String itemSpecId,
                             HttpServletRequest request, HttpServletResponse response) {

        if (StringUtils.isBlank(userId) || StringUtils.isBlank(itemSpecId)){
            return WJWJSONResult.errorMsg("参数不能为空");
        }

        // TODO 用户在页面删除购物车中的商品数据，如果此时用户已经登录，则需要同步删除后端购物车中的商品

        return WJWJSONResult.ok();
    }

}
